/**
 * 
 */
package de.guidoludwig.jtm.client.shows;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import com.jgoodies.binding.beans.BeanAdapter;
import com.jgoodies.binding.value.ValueHolder;
import com.jgoodies.binding.value.ValueModel;

import de.guidoludwig.af.AbstractHomeModel;
import de.guidoludwig.jtm.domain.Show;
import de.guidoludwig.jtm.server.AbstractRepository;
import de.guidoludwig.jtm.server.ShowRepository;

/**
 * @author guido
 *
 */
public class ShowsHomeModel extends AbstractHomeModel<Show>{

	private static ShowsHomeModel INSTANCE;
	private final ValueModel selectionHTMLModel;

	
	public static ShowsHomeModel getInstance() {
		if (INSTANCE == null) {
			INSTANCE = new ShowsHomeModel();
		}
		return INSTANCE;
	}

	
	public ShowsHomeModel() {
		super();
		selectionHTMLModel = new ValueHolder(null, true);
		getSelectionAdapter().addPropertyChangeListener(
				BeanAdapter.PROPERTYNAME_BEAN, new PropertyChangeListener() {
					@Override
					public void propertyChange(PropertyChangeEvent evt) {
						selectionHTMLModel.setValue(ShowHTMLFormat.INSTANCE
								.format(getSelectionAdapter().getBean()));
					}
				});
		selectionHTMLModel.setValue(ShowHTMLFormat.INSTANCE
				.format(getSelectionAdapter().getBean()));
	}
	
	public ValueModel getSelectionHTMLModel() {
		return selectionHTMLModel;
	}


	@Override
	protected AbstractRepository<Show> getRepository() throws Exception {
		return new ShowRepository();
	}
	
}
